package mvp.com.bbc.rcjavaretrofitdaggermvp.presenter;

import javax.inject.Inject;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.contact.ArtListContact;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.NetworkUtil;
import mvp.com.bbc.rcjavaretrofitdaggermvp.bean.ThemeListBean;
import mvp.com.bbc.rcjavaretrofitdaggermvp.model.ThemNameModel;

/**
 * Created by ${cbf} on 2017/12/2.
 */

public class ThemNamePresenter implements ArtListContact.ThemNamePresenter {
    private ArtListContact.ThemNameModel nameModel;
    private ArtListContact.ThemNameView nameView;

    @Inject
    public ThemNamePresenter(ArtListContact.ThemNameView nameView) {
        this.nameView = nameView;
        this.nameModel = new ThemNameModel();
    }

    @Override
    public void themNamePresneter() {
        nameModel.themNameModel()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<ThemeListBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull ThemeListBean listBean) {
                        nameView.themNameView(listBean);
                        NetworkUtil.onSuccess();
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        NetworkUtil.onError();

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
